/*
 * @Description:
 * @Version: 2.0
 * @Autor: Seven
 * @Date: 2023-09-22 15:22:12
 * @LastEditors: Seven
 * @LastEditTime: 2023-11-24 09:06:58
 */
import React, { memo, useState } from "react";
import {
  BankFilled,
  BulbFilled,
  SettingOutlined,
  BarChartOutlined,
} from "@ant-design/icons";
import type { MenuProps } from "antd";
import { Menu } from "antd";
import { useNavigate, useLocation } from "react-router-dom";

const MenuNavigation: React.FC = memo((props) => {
  const [current, setCurrent] = useState("");
  const navigation = useNavigate();
  const location = useLocation();

  //Menu数据根据pathname进行判断
  let items: MenuProps["items"] = [];
  if (location.pathname.includes("/monitoring")) {
    items = [
      {
        label: "线路概览",
        key: "/monitoring/route",
        icon: <BankFilled style={{ color: "#17b3cb", fontSize: "20px" }} />,
      },
      {
        label: "状态监视",
        key: "/monitoring/status",
        icon: <BulbFilled style={{ color: "#17b3cb", fontSize: "20px" }} />,
        children: [
          {
            label: "工务",
            key: "/monitoring/status/public",
          },
          {
            label: "供电",
            key: "/monitoring/status/power",
          },
          {
            label: "机电",
            key: "/monitoring/status/electromechanical",
          },
          {
            label: "通号",
            key: "/monitoring/status/call",
          },
          {
            label: "车辆",
            key: "/monitoring/status/vehicle",
          },
        ],
      },
      {
        label: "系统告警",
        key: "/monitoring/alarm",
        icon: (
          <SettingOutlined style={{ color: "#17b3cb", fontSize: "20px" }} />
        ),
        children: [
          {
            label: "告警统计",
            key: "/monitoring/alarm/statistics",
          },
          {
            label: "实时告警",
            key: "/monitoring/alarm/real",
          },
          {
            label: "历史告警",
            key: "/monitoring/alarm/history",
          },
        ],
      },
      {
        label: "运维指标",
        key: "/monitoring/operation",
        icon: (
          <BarChartOutlined style={{ color: "#17b3cb", fontSize: "20px" }} />
        ),
        children: [
          {
            label: "可靠性指标",
            key: "/monitoring/operation/reliability",
          },
          {
            label: "可靠性指标趋势",
            key: "/monitoring/operation/reliabilitytrend",
          },
          {
            label: "维修性指标",
            key: "/monitoring/operation/maintainability",
          },
          {
            label: "维修性指标趋势",
            key: "/monitoring/operation/maintainabilitytrend",
          },
          {
            label: "安全性指标",
            key: "/monitoring/operation/security",
          },
          {
            label: "安全性指标趋势",
            key: "/monitoring/operation/securitytrend",
          },
        ],
      },
    ];
  } else if (location.pathname.includes("/analyse")) {
    items = [
      {
        label: "首页",
        key: "/analyse/home",
        icon: <BankFilled style={{ color: "#17b3cb", fontSize: "20px" }} />,
      },
      {
        label: "设备故障分析",
        key: "/analyse/failure",
        icon: <BulbFilled style={{ color: "#17b3cb", fontSize: "20px" }} />,
        children: [
          {
            label: "故障趋势",
            key: "/analyse/failure/trendency",
          },
          {
            label: "故障类型分布",
            key: "/analyse/failure/type",
          },
          {
            label: "故障诊断",
            key: "/analyse/failure/diagnoosis",
          },
          {
            label: "故障分析",
            key: "/analyse/failure/analysis",
          },
          // {
          //   label: "故障预测",
          //   key: "/analyse/failure/prediction",
          // },
        ],
      },
      {
        label: "设备健康分析",
        key: "/analyse/heathy",
        icon: (
          <SettingOutlined style={{ color: "#17b3cb", fontSize: "20px" }} />
        ),
        children: [
          {
            label: "线网设备健康分",
            key: "/analyse/heathy/score",
          },
          {
            label: "车站设备健康分",
            key: "/analyse/heathy/station",
          },
        ],
      },
      {
        label: "设备检修分析",
        key: "/analyse/maintence",
        icon: (
          <BarChartOutlined style={{ color: "#17b3cb", fontSize: "20px" }} />
        ),
        children: [
          {
            label: "检修成本分析",
            key: "/analyse/maintence/cost",
          },
          {
            label: "供应商分析",
            key: "/analyse/maintence/vendor",
          },
        ],
      },
    ];
  } else if (location.pathname.includes("/operation")) {
    items = [
      {
        label: "工单管理",
        key: "/operation/work",
        icon: <BankFilled style={{ color: "#17b3cb", fontSize: "20px" }} />,
        children: [
          {
            label: "故障提报",
            key: "/operation/work/hand",
          },
          {
            label: "故障工单",
            key: "/operation/work/break",
          },
          {
            label: "检修工单",
            key: "/operation/work/repair",
          },
        ],
      },
      {
        label: "检修计划",
        key: "/operation/repair",
        icon: <BulbFilled style={{ color: "#17b3cb", fontSize: "20px" }} />,
        children: [
          {
            label: "年度计划",
            key: "/operation/repair/year",
          },
          {
            label: "月度计划",
            key: "/operation/repair/month",
          },
          {
            label: "周计划",
            key: "/operation/repair/week",
          },
        ],
      },
      {
        label: "设备管理",
        key: "/operation/equip",
        icon: (
          <SettingOutlined style={{ color: "#17b3cb", fontSize: "20px" }} />
        ),
        children: [
          {
            label: "设备台账",
            key: "/operation/equip/ledger",
          },
          {
            label: "设备登记",
            key: "/operation/equip/regist",
          },
        ],
      },
      {
        label: "专家知识库",
        key: "/operation/know",
        icon: (
          <BarChartOutlined style={{ color: "#17b3cb", fontSize: "20px" }} />
        ),
      },
    ];
  } else if (location.pathname.includes("/emergency")) {
    items = [
      {
        // label: "应急管理中心",//暂时隐藏导航栏
        key: "/emergency",
        // icon: <BankFilled style={{ color: "#17b3cb", fontSize: "20px" }} />,
        children: [
          {
            label: "应急管理中心",
            key: "/emergency/center",
          },
        ],
      },
    ];
  } else if (location.pathname.includes("/safety")) {
    items = [
      {
        // label: "安全防护中心",
        key: "/safety",
        // icon: <BankFilled style={{ color: "#17b3cb", fontSize: "20px" }} />,
        children: [
          {
            label: "安全防护中心",
            key: "/safety/defend",
          },
        ],
      },
    ];
  } else {
    items = [
      {
        label: "线路概览",
        key: "/monitoring/route",
        icon: <BankFilled style={{ color: "#17b3cb", fontSize: "20px" }} />,
      },
      {
        label: "状态监视",
        key: "/monitoring/status",
        icon: <BulbFilled style={{ color: "#17b3cb", fontSize: "20px" }} />,
      },
      {
        label: "系统告警",
        key: "/monitoring/alarm",
        icon: (
          <SettingOutlined style={{ color: "#17b3cb", fontSize: "20px" }} />
        ),
      },
      {
        label: "运维指标",
        key: "/monitoring/operation",
        icon: <BulbFilled style={{ color: "#17b3cb", fontSize: "20px" }} />,
      },
    ];
  }
  const onClick: MenuProps["onClick"] = (e) => {
    setCurrent(e.key);
    navigation(e.key);
  };
  const onSelectHandle = (e: any) => {
    console.log(e, "123");
  };
  return (
    <Menu
      onClick={onClick}
      selectedKeys={[current]}
      mode="horizontal"
      items={items}
      onSelect={onSelectHandle}
    />
  );
});

export default MenuNavigation;
